home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_bas / netuser.zip / DATA / VB / NetUser / 32-Bit / Netuser.bas
Encoding:
BASIC Source File  |  1995-12-15  |  1.3 KB  |  50 lines

  1. Attribute VB_Name = "NetworkUser"
  2. Option Explicit
  3. '
  4. '   This module will return the user name of the person who signed into
  5. '   the system. This module should work with the Windows 95 and Windows NT
  6. '   operating systems.
  7. '
  8. '   This module was tested under VB 4.0. It should work fine for any VBA
  9. '   language.
  10. '
  11. ''''
  12. '
  13. '   Declare variables needed
  14. '
  15. Private glngReturnStatus As Long
  16. Private Const SUCCESS = 1&
  17. Private Const FAILURE = 0&
  18.  
  19. Declare Function ADV_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal strUser As String, lngBuffer As Long) As Long
  20.  
  21. Function NetworkUserID() As String
  22. '   This routine will get the name of the user signed onto the network.
  23. '   If no username is found it will return an UnknownUser string.
  24. '
  25.     Dim lngBufferSize As Long
  26.     Dim strUser As String
  27.     
  28.     On Error GoTo NetworkUserID_EH
  29.  
  30.     NetworkUserID = "UnknownUser"
  31.     
  32.     lngBufferSize = 255
  33.     strUser = Space$(lngBufferSize)
  34.  
  35.     glngReturnStatus = ADV_GetUserName(strUser, lngBufferSize)
  36.     If glngReturnStatus = SUCCESS Then
  37.         strUser = Left$(strUser, lngBufferSize - 1)
  38.     Else
  39.         Err = glngReturnStatus
  40.     End If
  41.     NetworkUserID = strUser
  42.     Exit Function
  43.  
  44. NetworkUserID_EH:
  45.     NetworkUserID = "ErrorInCall"
  46.     Exit Function
  47. End Function
  48.  
  49.  
  50.